<template>
	<view style="height: 100vh; background-color: #FFFFFF;">
		<!-- 领取到任务的，修改任务状态 -->
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" :title="'检测详情'"></u-navbar>
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="changeTab"></u-tabs>
		<uni-search-bar v-model="equipmentName" @confirm="initView" @input="initView" placeholder="请输入设备名称"></uni-search-bar>
		<uc-content :loading="loading">
			<view>
				<view v-if="taskList.length<1" class="view-center">
					<u-empty text="数据为空" mode="list"></u-empty>
				</view>
				<view v-else>
					<view class="list-item" v-for="(item,index) in taskList" :key="index">
						<view class="list-top ">
							<view class="list-left">{{ item.equipmentName }}</view>
						</view>
						<view class="list-center u-line-3">
							<view>地点: {{ item.address}}</view>
							<view>设备编码: {{item.code}}</view>
							<view>检测状态: {{statusFormat(item.status)}}</view>
						</view>
						<view v-if="item.status == '01' && item.isvideo == '30' && item.mark" style="color: red;">
							{{item.mark}}
						</view>
						<view class="list-bottom">
							<view></view>
							<view style="width: 80%;">
								<u-button v-if="item.status != '40'" :disabled="item.status == '40'" @click="reportHiddenDanger(item)" type="primary" shape="square" style="width: 30%; float: right; height: 30px;line-height: 30px; font-size: 12px;">上报隐患</u-button>
								<u-button v-if="(item.isvideo=='01' || item.isvideo=='10') && item.status != '40'" @click="recording(item)" :disabled="(item.status != '01' && item.isvideo=='01') || (item.status != '20' && item.isvideo=='10')" type="primary" shape="square" style="margin-right: 5px; width: 30%; float: right; height: 30px;line-height: 30px; font-size: 12px;">拍摄视频</u-button>
								<u-button v-if="item.isvideo=='40' && item.status == '01'" @click="sbFire(item)" type="primary" shape="square" style="margin-right: 5px; width: 30%; float: right; height: 30px;line-height: 30px; font-size: 12px;">非测试</u-button>	
								<u-button v-if="item.isvideo=='40' && item.status == '01'" @click="wbCheck(item)" type="primary" shape="square" style="margin-right: 5px; width: 30%; float: right; height: 30px;line-height: 30px; font-size: 12px;">测试</u-button>
							</view>
						</view>
					</view>
					<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
				</view>
			</view>
		</uc-content>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '未检测'
				}, {
					name: '已检测'
				}],
				show: false,
				taskId: "",
				equipmentTypeId: "",
				standardId:0,
				taskList: [],
				statusOptions: [],
				equipmentName: "",
				pageNum: 0,
				finished: false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多数据了'
				},
				loading: false,
				current: 0,
				value: '20'
			}
		},
		onLoad(e) {
			this.taskId=e.taskId	
			this.equipmentTypeId=e.devType
			// this.standardId=e.id
		},
		onShow() {
			this.initView()
		},
		methods: {
			//非测试
			sbFire(item) {
				this.utils.request("/api/app/mainInfoData/wbFire", {
					ucId: item.equipmentId
				}, "post", "app", true).then(res => {
					console.log(res)
				}).catch(error => {
					console.log(error)
				})
			},
			//测试
			wbCheck(item) {
				this.utils.request("/api/app/examine/examineCheck", {
					ucId: item.equipmentId
				}, "post", "app", true).then(res => {
					console.log(res)
				}).catch(error => {
					console.log(error)
				})
			},
			statusFormat(data) {
				return this.selectDictLabel(this.statusOptions, data);
			},
			recording(item){
				window.native.ExamineRecordVideo({id:item.id, taskId: item.taskId},res => {
					this.initView()
				});
			},
			//隐患上报
			reportHiddenDanger(item){
				uni.navigateTo({
				    url: '/pages/testing/examineHiddenDanger?standardId='+this.standardId + "&equipmentId=" + item.equipmentId
				});
			},
			initView() {
				this.loading = true
				this.taskList = []
				this.pageNum = 0
				this.getDicts("equip_main_status").then(response => {
				    this.statusOptions = response.data.data;
				});
				this.getTaskPage()
			},
			changeTab(index) {
				this.current = index
				switch (this.current) {
					case 0:
						this.value = '20'
						break;
					case 1:
						this.value = '40'
						break;
					case 2:
						this.value = '01'
						break;
					default :
					 break;
				}
				this.initView()
			},
			getTaskPage() {
				let _this = this
				return new Promise((resolve, reject) => {
					_this.utils.request("/api/app/examine/getInExamineEquipmentList", {
						pageNum: this.pageNum,
						pageSize: 10,
						status: this.value,
						taskId: this.taskId,
						equipmentTypeId: this.equipmentTypeId
					}, "post", "app", true).then(res => {
						console.log(res)
						_this.taskList.push(...res.data)
						++_this.pageNum
						_this.finished = (this.pageNum >= res.data.pages);
						if (_this.finished) {
							_this.status = 'nomore';
						}
						this.loading = false
						resolve(res)
					}).catch(error => {
						this.loading = false
						reject(error)
					})
				})
			},
			onReachBottom() {
				if (this.finished) return;
				this.status = 'loading';
				this.getTaskPage().then(res => {
					if (this.finished) this.status = 'nomore';
					else this.status = 'loading';
				}).catch(error => {
					this.status = 'nomore';
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uview-ui/libs/css/style.components.scss";

	.list-item {
		padding: 30rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px solid;

		.list-top {
			@include vue-flex;
			justify-content: space-between;
			align-items: center;

			.list-left {
				font-weight: bold;
				font-size: 34rpx;
			}

			.list-right {
				font-size: 30rpx;
				line-height: 34rpx;
				color: #999999;
			}
		}

		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}

		.list-bottom {
			display: flex;
			margin-top: 20rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #999999;
		}
	}
</style>
